package com.property.manage.controller.schedule;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.owner.OwnerVo;
import com.property.manage.model.schedule.ScheduleEntity;
import com.property.manage.model.schedule.ScheduleVo;
import com.property.manage.service.owner.OwnerService;
import com.property.manage.service.schedule.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "值班管理")
@RestController
@RequestMapping("/schedule")
@AllArgsConstructor
@Validated
public class ScheduleController {

    private ScheduleService scheduleService;


    @ApiOperation("值班列表")
    @GetMapping("/page")
    public CustomPage<ScheduleVo> page(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                       @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                       @ApiParam("值班日期") @RequestParam(value = "datyDate", required = false) String datyDate,
                                       @ApiParam("小区id") @RequestParam(value = "quarterId", required = false) Integer quarterId,
                                       @ApiParam("类型 1 保洁 2保安") @RequestParam(value = "type")@NotNull(message = "类型不能为空") Integer type){
        return scheduleService.schedulePage(pageNo, pageSize,type, datyDate,quarterId);
    }



    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@ApiParam("业主类型 1保洁 2保安")@RequestParam(value = "type")@NotNull(message = "类型不能为空") Integer type,
                    @ApiParam(" 1 早班 2 中班 3晚班 4白班 5晚班")@RequestParam(value = "frequency")@NotNull(message = "班次不能为空") Integer frequency,
                    @ApiParam(" 值班人员 多人用‘、’隔开")@RequestParam(value = "personnel")@NotBlank(message = "班次不能为空") String personnel,
                    @ApiParam(" 值班区域")@RequestParam(value = "address")@NotBlank(message = "值班区域不能为空") String address,
                    @ApiParam(" 值班日期 yyyy-MM-dd")@RequestParam(value = "dutyDate")@NotBlank(message = "值班日期不能为空") String dutyDate,
                    @RequestParam(value = "phone")@NotBlank(message = "手机号码不能为空") String phone,
                    @ApiParam("小区id")@RequestParam(value = "villageId") @NotNull(message = "小区id不能为空")Integer villageId

    ){
        scheduleService.add(frequency,personnel,address,type,dutyDate,villageId,phone);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,@ApiParam("业主类型 1保洁 2保安")@RequestParam(value = "type")@NotNull(message = "类型不能为空") Integer type,
                       @ApiParam(" 1 早班 2 中班 3晚班 4白班 5晚班")@RequestParam(value = "frequency")@NotNull(message = "班次不能为空") Integer frequency,
                       @ApiParam(" 值班人员 多人用‘、’隔开")@RequestParam(value = "personnel")@NotBlank(message = "班次不能为空") String personnel,
                       @ApiParam(" 值班区域")@RequestParam(value = "address")@NotBlank(message = "值班区域不能为空") String address,
                       @ApiParam(" 值班日期 yyyy-MM-dd")@RequestParam(value = "dutyDate")@NotBlank(message = "值班日期不能为空") String dutyDate,
                       @RequestParam(value = "phone")@NotBlank(message = "手机号码不能为空") String phone,
                       @ApiParam("小区id")@RequestParam(value = "villageId") @NotNull(message = "小区id不能为空")Integer villageId    ){
       scheduleService.update(id,frequency,personnel,address,type,dutyDate,villageId,phone);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("业主id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        scheduleService.delete(id);
    }

}
